package pers.netty.chat.server;


import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * @author 李醴茝
 */
@Slf4j
@Service
public class ChatServerHandler extends ChannelInboundHandlerAdapter {

    /**
     * 建立连接时
     */
    @Override
    public void channelActive(final ChannelHandlerContext ctx) {
        log.info("CHANNEL_ACTIVE " + ctx.channel().remoteAddress());
    }

    /**
     * 收到消息
     *
     * @param ctx
     * @param msg
     */
    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) {
        log.info("msg:{}", msg.toString());
        ctx.writeAndFlush(msg);
    }

}
